package fr.ants.view.renderer.pokemon;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;

import fr.ants.model.Resource;
import fr.ants.view.panel.Canvas;
import fr.ants.view.renderer.ResourceRenderer;

/**
 * <p>Renders a nest with an image from Pokemon.</p> 
 *
 * @author Vianney DUPOY DE GUITARD
 */
public class ResourcePokemonRenderer implements ResourceRenderer {

	/** The image representing the resource full. */
	private BufferedImage resourceFullImg;

	/** The image representing the resource with half of the food. */
	private BufferedImage resourceHalfImg;

	/** The image representing the resource almost empty. */
	private BufferedImage resourceLessImg;

	/** Default constructor, loads the image. */
	public ResourcePokemonRenderer() {
		try {
			resourceFullImg = ImageIO.read(getClass().getResourceAsStream("/draw/poke/resource_full.png"));
			resourceHalfImg = ImageIO.read(getClass().getResourceAsStream("/draw/poke/resource_half.png"));
			resourceLessImg = ImageIO.read(getClass().getResourceAsStream("/draw/poke/resource_less.png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/** {@inheritDoc} */
	public void draw(int x, int y, Graphics2D g, Resource resource) {
		float ratio = resource.getAmount() / resource.getCapacity() * 100;
		if (ratio > 50) {
			g.drawImage(resourceFullImg, x * Canvas.NODE_SIZE, y * Canvas.NODE_SIZE, Canvas.NODE_SIZE, Canvas.NODE_SIZE, null);
		} else if (ratio > 20) {
			g.drawImage(resourceHalfImg, x * Canvas.NODE_SIZE, y * Canvas.NODE_SIZE, Canvas.NODE_SIZE, Canvas.NODE_SIZE, null);
		} else {
			g.drawImage(resourceLessImg, x * Canvas.NODE_SIZE, y * Canvas.NODE_SIZE, Canvas.NODE_SIZE, Canvas.NODE_SIZE, null);
		}
	}
}